#include <iostream>
#include <future>
#include <thread>
#include <system_error>

void test_promise_future() {
    try {
        std::promise<int> p;
        std::future<int> f = p.get_future();
        
        std::cout << "Testing promise/future in main thread..." << std::endl;
        
        // 在同一个线程中设置值
        p.set_value(42);
        
        int result = f.get();
        std::cout << "Result: " << result << std::endl;
        
        std::cout << "Test passed" << std::endl;
        
    } catch (const std::system_error& e) {
        std::cout << "System error in test: " << e.what() << std::endl;
    }
}

int main() {
    test_promise_future();
    return 0;
}